// OUTDOOR SECTION SCRIPT
//    Section: X = 0, Y = 0: North Ateria

// This is the special encounter script for this town.
// The states INIT_STATE and START_STATE have
// meanings that are described in the documenation. States you write
// yourself should be numbered from 10-100.

beginoutdoorscript;

variables;

int i,j,k;
string dlgstr;

body;

beginstate INIT_STATE;
// This state called whenever this section is loaded into memory.
if (get_flag(6,0) != 0)
	set_flag(250,0,2);
break;

beginstate START_STATE;
// Starting state of the section, called every turn the party 
// stands inside this section until you change the state.
break;


beginstate 10;
if (get_flag(200,0) == 0) {
	reset_dialog();
	add_dialog_str(0,"You were told that Umbratium used to be an administrative center, before people started to leave Ateria. The province was dangerous enough even then to require two walls. This outer wall is covered with moss and is missing more than a few rocks.",0);
	add_dialog_str(1,"The land is covered in a thick fog, extending as high as the bleakly overcast sky. The ground almost looks as though you are in a cave.",0);
	add_dialog_str(2,"You may wish to forage for some herbs before you move on. The road looks dangerous, and it would be well to be fully equipped in case of an emergency.",0);
	add_dialog_str(3,"(Use your ability Make Potions to look around for herbs.)",0);
	set_flag(200,0,run_dialog(1));
	}
break;

beginstate 11;
	message_dialog("As you walk, several large wolves slink out of the forest.","The residents of Umbratium were right: this forest does have a number of dangerous wolves, some much bigger than those you've seen in more civilized lands. Can they be responsible for the disappearances?");
break;

beginstate 12;
if (get_flag(200,1) == 0) {
	set_flag(200,1,1);
	place_out_spec_enc(0,23,33);
	}
break;

beginstate 13;
if (get_flag(200,2) == 0) {
	set_flag(200,2,1);
	place_out_spec_enc(1,29,41);
	}
break;

beginstate 14;
if (get_flag(200,3) == 0) {
	set_flag(200,3,1);
	place_out_spec_enc(2,29,41);
	}
break;

beginstate 15;
	reset_dialog();
	add_dialog_str(0,"Do you wish to leave Ateria, ending this mission?",0);
	add_dialog_choice(0,"Yes. It's time to go.");
	add_dialog_choice(1,"No. More needs to be done here.");
	if (run_dialog(1) == 2) {
		block_entry(1);
		message_dialog("You turn back. Duty calls you to finish your mission before you leave.","");
		}
	else {
		// Endings.
		
		i = 0;
		while (i <= 3) {
			// First, restore the party's original stats.
			alter_stat(i,6,get_flag(260 + i,0));
			alter_stat(i,12,get_flag(260 + i,1));
			alter_stat(i,11,get_flag(260 + i,2));
			alter_stat(i,13,get_flag(260 + i,3));
			alter_stat(i,16,get_flag(260 + i,4));
			alter_stat(i,5,get_flag(260 + i,5));
			alter_stat(i,14,get_flag(260 + i,6));
			alter_stat(i,15,get_flag(260 + i,7));
			
			alter_stat(i,7,0 - get_flag(260 + i,0)); 
			alter_stat(i,17,0 - get_flag(260 + i,1));
			alter_stat(i,7,0 - get_flag(260 + i,2));
			alter_stat(i,7,0 - get_flag(260 + i,3));
			alter_stat(i,7,0 - get_flag(260 + i,4));
			alter_stat(i,4,0 - get_flag(260 + i,5));
			alter_stat(i,17,0 - get_flag(260 + i,6));
			alter_stat(i,1,0 - get_flag(260 + i,7));
			
			// Restore the spells, too.
			k = 0;
			while (k <= 19) {
				change_spell_level(i,0,k,get_flag(271 + i,k));
				k = k + 1;
				}
			k = 0;
			while (k <= 19) {
				change_spell_level(i,1,k,get_flag(275 + i,k));
				k = k + 1;
				}
			i = i + 1;
			}
		
		// Party never met Faustulus.
		if (get_flag(2,1) == 0) {
			reset_dialog();
			add_dialog_str(0,"You leave Ateria without ever meeting with the empire's man in Timoria. When you report back to the governor of Dacia, he seems very disappointed and a bit angry. You completely abandoned your mission and walked away.",0);
			add_dialog_str(1,"He sends a new messenger to check on the status of Ateria, but the messenger returns saying that the towns are all gone. Umbratium and Timoria were destroyed, and he said that the only other path, one into the mountains, led nowhere.",0);
			add_dialog_str(2,"You receive only minimal punishment for having completely failed in this task, but you never find out what was going on in Ateria. The rumors eventually dry up, and you are long dead before the same stories start being told again.",0);
			add_dialog_str(3,"THE END.",0);
			run_dialog(1);
			end_scenario(0);
			}
		
		// Party never met Putidus.
		if (get_flag(6,0) == 0) {
			reset_dialog();
			add_dialog_str(0,"You leave Ateria without ever meeting Lord Putidus. When you report back to the governor of Dacia, he seems very disappointed and almost angry. You abandoned your mission and walked away.",0);
			add_dialog_str(1,"He sends a new messenger to check on the status of Ateria, but the messenger returns saying that the towns are all gone. Umbratium and Timoria were destroyed, and no one was left inside them.",0);
			add_dialog_str(2,"He also said that the path into the mountains led nowhere. He could not find any sign of Castle Putideum, where Lord Putidus was reputed to live.",0);
			add_dialog_str(3,"You receive only minimal punishment for having failed in this task, but you never find out what was going on in Ateria. The rumors eventually dry up, and you are long dead before the same stories start being told again.",0);
			add_dialog_str(4,"THE END.",0);
			run_dialog(1);
			end_scenario(0);
			}
		
		// Party escaped from the dungeon but did nothing.
		if (get_flag(250,2) == 0) {
			reset_dialog();
			add_dialog_str(0,"You leave Ateria, and the journey back to the governor of Dacia is uneventful, except for a few nightmares in which you hear the same voice as spoke to you in your dream in prison. It grumbles distantly, but you can't understand. It sounds angry, though.",0);
			add_dialog_str(1,"After you report, the governor sends another messenger back to check on the status of Ateria, and the messenger returns confirming what you saw: Umbratium and Timoria were destroyed.",0);
			add_dialog_str(2,"He also said that the path into the mountains led nowhere. He could not find any sign of Castle Putideum, even though you gave specific directions. It simply was not there.",0);
			add_dialog_str(3,"You receive no reward for your completion of this task. Your story is hardly honorable or valorous, as you left most things undone that would have earned you honor, but there is little shame, either: you did what the governor requested and no more.",0);
			add_dialog_str(4,"You are reassigned, and soon, you finish your military service and return home. Questions still linger about Ateria, but you are long dead before similar stories begin rising out of Dacia again, when it has become known by a new name: Transylvania.",0);
			add_dialog_str(5,"THE END.",0);
			run_dialog(1);
			end_scenario(1);
			}
	
		// Party defeated Putidus.
		reset_dialog();
		add_dialog_str(0,"You leave Ateria, and the journey back to the governor of Dacia is uneventful, except for a single dream in which you hear the same voice as spoke to you in your dream in prison. It speaks to you:",0);
		clear_buffer();
		append_string("_");
		append_char_name(i);
		append_string(", many have died here. Ateria is destroyed. You could not stop the destruction except by lying. You have gained no honor here, but perhaps there was no honor to be gained. You have gained no shame, either._");
		get_buffer_text(dlgstr);
		add_dialog_str(1,dlgstr,0);
		add_dialog_str(2,"You report back to the governor. Afterwards, he sends another messenger back to check on the status of Ateria, and the messenger returns confirming what you saw: Umbratium and Timoria were destroyed.",0);
		add_dialog_str(3,"He also said that the path into the mountains led nowhere. He could not find any sign of Castle Putideum, even though you gave specific directions. It simply was not there.",0);
		add_dialog_str(4,"You receive a modest reward for your work. You can't bring yourself to tell the governor the full story, so you claim that you found Faustulus dead before you attacked Putidus. You sound more heroic than you were, but no one suspects you are lying.",0);
		add_dialog_str(5,"You are reassigned, and soon, you finish your military service and return home. Some loose ends remain in Ateria: since Castle Putideum vanished, no one could destroy his records or prevent others from finding out what Putidus did and doing it again.",0);
		run_dialog(1);
		
		message_dialog("However, you are long dead before similar stories begin rising out of Dacia again, when it has become known by a new name: Transylvania.","THE END.");
		
		end_scenario(1);
		}
break;